<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>每日餐品安全检查项目</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-table
            :data="treeList"
            row-key="id"
            :default-expand-all="isExpandAll"
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        >
          <el-table-column prop="number" label="序号" width="50" align="center"></el-table-column>
          <el-table-column prop="name" label="检查项目"></el-table-column>
          <el-table-column prop="name" align="center" width="180" label="责任人" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <el-tag size="mini" v-for="item in scope.row.user_ids" :key="item.id">{{item.realname}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="140">
            <template slot-scope="scope">
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="optionId=scope.row.id,dayOptionVisible=true"
              >修改
              </el-button>
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="deletefn(scope.row)"
              >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">返回</el-button>
        <el-button @click.native="optionId=0,dayOptionVisible=true" size="small" type="primary" plain>新增检查项目</el-button>
      </div>
      <dayOptionEdit :visible.sync="dayOptionVisible" @InitFn="getList" :optionId="optionId"></dayOptionEdit>
    </div>
  </div>
</template>

<script>
import {dayCheckOptionIndex, dayCheckOptionDelete} from "@/api/admin/food"
import dayOptionEdit from "./dayOptionEdit";
export default {
  props: ['visible'], // recruitmentType examine 审核
  components: {dayOptionEdit},
  data() {
    return {
      dialogVisible: false,
      treeList: [],
      isExpandAll: false,
      dayOptionVisible:false,
      optionId: 0
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.getList()
      }
    }
  },
  created() {

  },
  methods: {
    getList() {
      dayCheckOptionIndex({p: 0}).then(res => {
        console.log('res:', res)
        this.treeList = this.$handleTree(res.list, 'id', 'parent_id');
      })
    },
    checkEditFn() {
      if (!this.infoForm[this.itemlable]) {
        this.$message.error('请填写信息');
        return
      }
      this.$emit('checkList', {name: this.itemlable, val: this.infoForm[this.itemlable]})
      this.closePOpup()
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    editCate(type, row) {
      this.optionType = type
      this.optionData = row
      this.patrolVisible = true
    },
    deletefn(row) {
      this.$confirm(`确认删除【${row.number}】, 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.detelRespon(row.id)
      }).catch(() => {
      })
    },
    detelRespon(id){
      dayCheckOptionDelete({id:id}).then(res=>{
        if(!res.code){
          this.$message.success(res.msg)
          this.getList()
        }
      })
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 750px;
  height: 70%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
</style>


